from django.db import models
from OpSystem.settings import AUTH_USER_MODEL
from account.models import MyUser
import datetime

# Create your models here.
'''
password: pbkdf2_sha256$30000$VcSOOXS5h1sC$aAeByvxUqvuSpCKCOLvbrFgOcVgOQv3nhxWjq9rWkuI=
          pbkdf2_sha256$30000$wn46f90PmbUR$bTGzhAhgIShHqtNHotbE5ajJV+N9tFXTpXt3pBzTi2k=
          pbkdf2_sha256$30000$wn46f90PmbUR$bTGzhAhgIShHqtNHotbE5ajJV+N9tFXTpXt3pBzTi2k=
'''

class Hosts(models.Model):
    user = models.ManyToManyField(AUTH_USER_MODEL)
    hostcode = models.CharField(max_length=100,unique=True)
    ip_wan = models.CharField(max_length=100)
    ip_lan = models.CharField(blank=True, max_length=100)
    configureations = models.CharField(max_length=100)
    os = models.CharField(blank=True, max_length=100)
    release = models.CharField(max_length=100)
    create_date = models.DateField(default=datetime.datetime.today)
    expice_date = models.DateField(blank=True,null=True)
    abandon_date = models.DateTimeField(blank=True,null=True)

    class meta:
        db_table = 'host'

    def __str__(self):
        return self.hostcode

class Items(models.Model):
    item_name = models.CharField(max_length=300)
    item_description = models.TextField(blank=True)
    item_soft = models.ForeignKey('ItemSofts')
    user = models.ManyToManyField(AUTH_USER_MODEL)
    # item_pm_charge = models.ForeignKey(AUTH_USER_MODEL)
    # item_pm = models.ManyToManyField(AUTH_USER_MODEL)
    # item_manager_chage = models.ForeignKey(AUTH_USER_MODEL)
    # item_manager = models.ManyToManyField(AUTH_USER_MODEL)
    # item_dev_charge = models.ForeignKey(AUTH_USER_MODEL)
    # item_dev = models.ManyToManyField(AUTH_USER_MODEL)
    # item_op_charge = models.ForeignKey(AUTH_USER_MODEL)
    # item_op = models.ManyToManyField(AUTH_USER_MODEL)

    class meta:
        db_table = 'Item'

    def __str__(self):
        return self.item_name

class softs(models.Model):
    soft_name = models.CharField(blank=True, max_length=100)
    soft_version = models.CharField(blank=True, max_length=100)

    class meta:
        db_table = 'softs'
        unique_together = ('soft_name','soft_version')  # todo 检查 联合唯一不生效

    def __str__(self):
        return '%s,%s'%(self.soft_name,self.soft_version)

class ItemSofts(models.Model):
    soft_name = models.CharField(blank=True,max_length=100) #安装程序名称
    soft_path = models.CharField(blank=True, max_length=100)
    soft_conf_path = models.CharField(blank=True,max_length=100,default='/default/')
    #soft_conf = models.CharField(blank=True, max_length=100)
    soft = models.ForeignKey(softs)
    host = models.ForeignKey(Hosts)

    class meta:
        db_table = 'ItemSoft'

    def __str__(self):
        return '[%s] [%s] [%s]'%(self.soft_name,self.soft_path,self.host)

class CodePush(models.Model):
    item = models.ForeignKey(Items)
    codeversion = models.CharField(blank=True, max_length=100)
    # status = models.CharField(choise('待发布','待审核','running'), max_length=100)
    code_list = models.TextField()
    code_log = models.TextField()
    user = models.ManyToManyField(AUTH_USER_MODEL)
